<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>first_scalar</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="explicit_operator_bool.html" title="explicit_operator_bool">
<link rel="next" href="ignore_unused.html" title="ignore_unused">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="explicit_operator_bool.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ignore_unused.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.first_scalar"></a><a class="link" href="first_scalar.html" title="first_scalar">first_scalar</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="first_scalar.html#core.first_scalar.overview">Overview</a></span></dt>
<dt><span class="section"><a href="first_scalar.html#core.first_scalar.examples">Examples</a></span></dt>
<dt><span class="section"><a href="first_scalar.html#core.first_scalar.reference">Reference</a></span></dt>
<dt><span class="section"><a href="first_scalar.html#core.first_scalar.history">History</a></span></dt>
</dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm7284"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Glen Fernandes
        </li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.first_scalar.overview"></a><a class="link" href="first_scalar.html#core.first_scalar.overview" title="Overview">Overview</a>
</h3></div></div></div>
<p>
        The header &lt;boost/core/first_scalar.hpp&gt; provides the function templates
        <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">first_scalar</span></code> that can be used to obtain
        a pointer to the first scalar element of an array. Given a pointer of type
        <code class="computeroutput"><span class="identifier">T</span><span class="special">*</span></code>
        they return a pointer of type <code class="computeroutput"><span class="identifier">remove_all_extents_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;*</span></code>.
        The functions are <code class="computeroutput"><span class="keyword">constexpr</span></code>
        and can be used in constant expressions.
      </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.first_scalar.examples"></a><a class="link" href="first_scalar.html#core.first_scalar.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
        The following function uses an allocator to allocate an array of arrays and
        constructs each scalar element in it.
      </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">alloc_construct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">first_scalar</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">&gt;</span>
<span class="keyword">auto</span> <span class="identifier">create</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">&amp;</span> <span class="identifier">allocator</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_traits</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;::</span><span class="keyword">template</span>
        <span class="identifier">rebind_alloc</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">[</span><span class="number">2</span><span class="special">][</span><span class="number">3</span><span class="special">]&gt;</span> <span class="identifier">other</span><span class="special">(</span><span class="identifier">allocator</span><span class="special">);</span>
    <span class="keyword">auto</span> <span class="identifier">ptr</span> <span class="special">=</span> <span class="identifier">other</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">(</span><span class="number">4</span><span class="special">);</span>
    <span class="keyword">try</span> <span class="special">{</span>
        <span class="identifier">boost</span><span class="special">::</span><span class="identifier">alloc_construct_n</span><span class="special">(</span><span class="identifier">other</span><span class="special">,</span>
            <span class="identifier">boost</span><span class="special">::</span><span class="identifier">first_scalar</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">to_address</span><span class="special">(</span><span class="identifier">ptr</span><span class="special">)),</span> <span class="number">24</span><span class="special">);</span>
    <span class="special">}</span> <span class="keyword">catch</span> <span class="special">(...)</span> <span class="special">{</span>
        <span class="identifier">other</span><span class="special">.</span><span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">ptr</span><span class="special">,</span> <span class="number">4</span><span class="special">);</span>
        <span class="keyword">throw</span><span class="special">;</span>
    <span class="special">}</span>
    <span class="keyword">return</span> <span class="identifier">ptr</span><span class="special">;</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.first_scalar.reference"></a><a class="link" href="first_scalar.html#core.first_scalar.reference" title="Reference">Reference</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">first_scalar</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="keyword">auto</span> <span class="identifier">first_scalar</span><span class="special">(</span><span class="identifier">T</span> <span class="special">(*</span><span class="identifier">p</span><span class="special">)[</span><span class="identifier">N</span><span class="special">])</span> <span class="keyword">noexcept</span><span class="special">;</span>

<span class="special">}</span> <span class="comment">/* boost */</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.first_scalar.reference.functions"></a><a class="link" href="first_scalar.html#core.first_scalar.reference.functions" title="Functions">Functions</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">constexpr</span>
            <span class="identifier">T</span><span class="special">*</span>
            <span class="identifier">first_scalar</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="identifier">p</span></code>.
                    </p></dd>
</dl>
</div></dd>
<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span>
            <span class="identifier">N</span><span class="special">&gt;</span>
            <span class="keyword">constexpr</span> <span class="keyword">auto</span>
            <span class="identifier">first_scalar</span><span class="special">(</span><span class="identifier">T</span> <span class="special">(*</span><span class="identifier">p</span><span class="special">)[</span><span class="identifier">N</span><span class="special">])</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="identifier">first_scalar</span><span class="special">(&amp;(*</span><span class="identifier">p</span><span class="special">)[</span><span class="number">0</span><span class="special">])</span></code>.
                    </p></dd>
</dl>
</div></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.first_scalar.history"></a><a class="link" href="first_scalar.html#core.first_scalar.history" title="History">History</a>
</h3></div></div></div>
<p>
        Glen Fernandes implemented <code class="computeroutput"><span class="identifier">first_scalar</span></code>.
        Peter Dimov suggested a change for GCC to support an additional <code class="computeroutput"><span class="keyword">constexpr</span></code> use.
      </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="explicit_operator_bool.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ignore_unused.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
